//
//  TKIMScoreMsgView.m
//  TKIM_标准版
//
//  Created by liupm on 16/3/1.
//  Copyright © 2016年 liupm. All rights reserved.
//

#import "TKIMScoreMsgView.h"
#import <CoreText/CoreText.h>

@implementation TKIMScoreMsgView


/**
 *  @Author lpm, 15-07-30 11:07:12
 *
 *  @brief  组装界面
 */
-(void)drawView
{
    [super drawView];
//    [self.backgroundImageView addSubview:self.messageLabel];
      [self.backgroundImageView addSubview:self.evaluateView];
}


-(TKIMKeFuEvaluateView *)evaluateView
{
    if (_evaluateView==nil) {
        _evaluateView = [[TKIMKeFuEvaluateView alloc] initWithFrame:CGRectMake(0, 0, 200, 130)];
    }
    return _evaluateView;
}


-(UILabel *)messageLabel
{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _messageLabel.font = [UIFont systemFontOfSize:15.0f];
        _messageLabel.textColor = [UIColor whiteColor];
        _messageLabel.numberOfLines = 0;
        _messageLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _messageLabel.backgroundColor = [UIColor clearColor];
    }
    return _messageLabel;
}


/**
 *  @Author lpm, 15-07-27 17:07:14
 *
 *  @brief  设置文字
 *
 *  @param text
 */
-(void)setMessage:(TKIMMessage *)message
{
    [super setMessage:message];

    self.backgroundImageView.userInteractionEnabled = YES;
    _evaluateView.dict = message.ext;
    _evaluateView.message = message;
    NSString* scoreStatus = message.ext[@"scoreStatus"];
    CGSize size = CGSizeMake(200, 160);
    if (scoreStatus&&[@"1" isEqualToString:scoreStatus]) {
        size = CGSizeMake(200, 130);
    }
    CGRect msgRect = [self getMsgFrame:message size:size];
    self.evaluateView.frame = msgRect;
}


/**
 *  @Author lpm, 15-10-26 17:10:01
 *
 *  @brief  播放声音
 *
 *  @param tap
 */
-(void)toScore:(UITapGestureRecognizer *)tap
{
//    [self routerEventWithName:TKIMToScoreEvent userInfo:nil];
}


/**
 *  @Author lpm, 15-11-06 11:11:05
 *
 *  @brief  行高
 *
 *  @param msg
 *
 *  @return
 */
+(CGFloat)heightForRow:(TKIMMessage *)msg
{
    id data=[[TKIMInterfaceHelper sharedInstance] valueForKeyData:TKIMSDK_KEFU_USER_DATA];
    NSInteger height = 160 ;
    if (data) {
    NSString* scoreStatus = msg.ext[@"scoreStatus"];
    NSString* time = msg.ext[@"scoreTime"];
    if (time&&[@"-1" isEqualToString:time]) {
        if (scoreStatus&&[@"1" isEqualToString:scoreStatus]) {
            height = 130 ;
        }
    }else{
        NSInteger newtime  = [[NSDate date] timeIntervalSince1970]*1000;
        NSInteger oldtime = [time integerValue];
        if ((oldtime-newtime)) {//可以评价的
            if (scoreStatus&&[@"1" isEqualToString:scoreStatus]) {
                height = 130 ;
            }
        }else{
            height = 130 ;
        }
    }
    }else{
        height = 130;
    }
    return   height + TKIMChatMsgPadding+26;
}


@end
